<template>
	<view class="mainCss">
		<view class="titleBox">
			<view class="titleLeft">

			</view>
			<view class="titleText">
				<text>我的</text>
			</view>
			<view class="titleRight">
			</view>
		</view>
		<view class="headBox">
			<view class="">
				<img :src="imageUrl" class="userHead">
			</view>
			<view class="userName">
				<button v-if="!isLogin" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">请先登录</button>
				<text v-else style="width: 100%;">{{nickName}}</text>
				<text v-if="!isLogin" style="font-size: 12px; color: #999999;">登录后可体验更多服务</text>
				<text v-else style="font-size: 12px; color: #999999;"></text>
			</view>
			<text class="more" @click="more" style="width: 50rpx;direction:rtl">更改</text>
			<uni-popup ref="popup" type="center" :animation="false">
				<form @submit="confirm">
					<view class="models">
						<button open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
							<img :src="imageUrl" class="userHead">
						</button>
						<view class="petName">
							<input type="nickname" v-model="nickname" class="weui-input" placeholder="请输入昵称" />
						</view>
					</view>
					<button form-type="submit">确认</button>
				</form>
			</uni-popup>
			<u-modal :show="show" @confirm="confirm" content="adadaf" ref="uModal" :asyncClose="true"
				showConfirmButton="false">
				
			</u-modal>
		</view>
		<view class="otherBox">
			<view class="other" @click="vip">
				<img src="../../static/my/vip.png" class="otherIcon">
				<text class="otherText">会员信息</text>
				<img src="../../static/home/right.png" class="otherMore">
			</view>
			<view class="other" @click="wallet">
				<img src="../../static/my/wallet.png" class="otherIcon">
				<text class="otherText">钱包</text>
				<img src="../../static/home/right.png" class="otherMore">
			</view>
		</view>
		<view class="otherBox1">
			<view class="other" @click="release">
				<img src="../../static/my/release.png" class="otherIcon">
				<text class="otherText">我的发布</text>
				<img src="../../static/home/right.png" class="otherMore">
			</view>
			<view class="other" @click="share">
				<img src="../../static/my/share.png" class="otherIcon">
				<text class="otherText">我的分享</text>
				<img src="../../static/home/right.png" class="otherMore">
			</view>
			<view class="other" @click="order">
				<img src="../../static/my/order.png" class="otherIcon">
				<text class="otherText">我的订单</text>
				<img src="../../static/home/right.png" class="otherMore">
			</view>
			<view class="other" @click="collect">
				<img src="../../static/my/collect.png" class="otherIcon">
				<text class="otherText">我的收藏</text>
				<img src="../../static/home/right.png" class="otherMore">
			</view>
		</view>
		<view class="otherBox2">
			<view class="other" @click="setting">
				<img src="../../static/my/setting.png" class="otherIcon">
				<text class="otherText">更多设置</text>
				<img src="../../static/home/right.png" class="otherMore">
			</view>
		</view>
	</view>
</template>

<script>
	// import WXBizDataCrypt from '../../utils/WXBizDataCrypt.js'

	import {
		toHandlerKey
	} from "vue";

	// import amap from '../../common/amap-wx.130.js';
	var common = require('../../api/common.js');
	export default {
		data() {
			return {
				isLogin: false,
				show: false,
				OpenID: '',
				infos: '',
				imageUrl: '',
				// code码
				code1: '',
				// openId,
				openId: '',
				// session_key
				session_key: '',
				nickName: ''

			}
		},
		onLoad() {},
		onShow() {

		},
		methods: {
			//打开弹出层
			open() {
				this.$refs.popup.open('top')
			},
			getPhoneNumber(e) {
				var that = this;
				console.log("aaa");
				console.log(e);
				// console.log(this.data.OpenID);
				wx.request({
					url: "https://ypsf.huashengzhuan.cn/Application/NewShopApi.ashx?action=GetPhoneNum ",
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					data: {
						code: e.detail.code,
						openID: getApp().globalData.openID
					},
					method: 'POST',
					success: function(resa) {
						that.isLogin = true;
						that.nickName = getApp().globalData.nickName;
						that.imageUrl = getApp().globalData.headImageUrl;
					}
				});
			},
			onChooseAvatar(e) {
				var that = this;
				debugger;
				console.log(e.detail.avatarUrl);
				that.uploadHeadImage(e.detail.avatarUrl);
			},
			uploadHeadImage(url) {
				debugger;
				uni.uploadFile({
					url: 'https://ypsf.huashengzhuan.cn/Application/NewShopApi.ashx?action=uploadSingleImage', // 仅为示例，非真实的接口地址
					filePath: url,
					name: 'file',
					header: {
						'Content-Type': 'form-data'
					},
					success: (res) => {
						debugger
						console.log(res);
						var aa = JSON.parse(res.data);
						getApp().globalData.headImageUrl = 'https://ypsf.huashengzhuan.cn' + aa.path;
						this.imageUrl = getApp().globalData.headImageUrl;
					}
				});
			},
			// more() {
			// 	this.show = true
			// },
			confirm() {
				var that = this;
				that.show = false;
				that.$refs.popup.close()
				wx.request({
					url: "https://ypsf.huashengzhuan.cn/Application/NewShopApi.ashx?action=getWxInfo",
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					data: {
						openID: getApp().globalData.openID,
						nickName: this.nickName,
						avatarUrl: this.imageUrl
					},
					method: 'POST',
					success: function(resa) {
						console.log(resa);
					}
				});
			},
			// 跳转到会员信息
			vip() {
				uni.navigateTo({
					url: '/pages/my/vip',
				})
			},
			// 跳转到钱包
			wallet() {
				uni.navigateTo({
					url: '/pages/my/wallet',
				})
			},
			// 跳转到我的发布
			release() {
				uni.navigateTo({
					url: '/pages/my/release',
				})
			},
			// 跳转到我的分享
			share() {
				uni.navigateTo({
					url: '/pages/my/share',
				})
			},
			// 跳转到我的订单
			order() {
				uni.navigateTo({
					url: '/pages/my/order',
				})
			},
			// 跳转到我的收藏
			collect() {
				uni.navigateTo({
					url: '/pages/my/collect',
				})
			},
			// 跳转到设置
			setting() {
				uni.navigateTo({
					url: '/pages/my/setting',
				})
			},
		}
	}
</script>

<style>
	@import '../../css/my.css';

	.userName button {
		width: 200rpx;
		margin: 0;
		padding: 0;
	}
</style>